layui.define([ 'form', 'laydate', 'table' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var excelTable = null;
    var index = layer.load(1, {
        shade: 0.5
    }); //loadding弹出层
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),excelTable)
            }
        },
        initTable:function(){
            excelTable = table.render({
                elem : '#excelTable',
                height : Lib.getTableHeight(1),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/excel/list.json', // 数据接口
                page : Lib.tablePage, // 开启分页
                limit : 10,
                done:function (res) {       //返回数据执行回调函数
                    layer.close(index);    //返回数据关闭loading
                },
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },
                    {

                        field : 'name',
                            title : '姓名',
                        align: 'center',
                        width:"120"
                    },{

                        field : 'identificationNumber',
                        title : '证件号',
                        align: 'center',
                        width:"180"
                    },
                    {

                        field : 'enterpriseName',
                            title : '在职单位',
                        align: 'center',
                        width:"300"
                    },
                    {

                        field : 'businessMatters',
                            title : '业务事项',
                        align: 'center',
                        width:"200"
                    },
                    /*{

                        field : 'processUserName',
                            title : '初审人',
                        align: 'center',
                        width:"105"
                    },
                    {

                        field : 'reviewUserName',
                            title : '复审人',
                        align: 'center',
                        width:"105"
                    },*/{
                        field: 'externalTaskId',
                        title: '申报流水号',
                        align: 'center',
                        width:"180"
                    }
                ] ]

            });

            table.on('checkbox(excelTable)', function(obj){
                var excel = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },
        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),excelTable,form);
            var btn = $("#" + id + "Search")
            btn.on('click', function () {
               // Lib.doSearchForm(form, tableIns, 1);
                var data = $("#searchForm").serializeJson();
                var index2 = layer.load(1, {
                    shade: 0.5
                }); //loadding弹出层
                excelTable.reload({
                    where: data,
                    done:function (res) {       //返回数据执行回调函数
                        layer.close(index2);    //返回数据关闭loading
                    }
                });
            });
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    var url = "/cms/excel/add.do";
                    Common.openDlg(url,"excel>新增");
                },
                edit : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"excelTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/excel/edit.do?id="+data.id;
                    Common.openDlg(url,"excel >编辑");
                },
                detailsExportDocument : function() {
                    layui.use([ 'excelApi' ], function() {
                        var testApi = layui.excelApi
                        Common.openConfirm("确认要导出这些企业数据?", function() {
                            testApi.detailsExportDocument($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                exportDocument : function() {
                    layui.use([ 'excelApi' ], function() {
                        var testApi = layui.excelApi
                        Common.openConfirm("确认要导出这些企业数据?", function() {
                            testApi.exportExcel($("#searchForm"), function(fileId) {
                                Lib.download(fileId);
                            })
                        })
                    });
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                }
        };
        $('.ext-toolbar').on('click', function() {
            var type = $(this).data('type');
            toolbar[type] ? toolbar[type].call(this) : '';
        });
        }
    }
    exports('index',view);

});